#include "mywindow.h"

MyWindow::MyWindow(QWidget *parent) : QWidget(parent) {
   this->setGeometry(100,100, 300,500);

    lcd = new QLCDNumber(this);
    lcd->setGeometry(100,30, 100,40);

    btnStart = new  QPushButton(this);
    btnStart->setGeometry(100,100, 100,30);
    btnStart->setText("Старт");

    edt = new QLineEdit(this);
    edt->setGeometry(100,10, 100,20);

    btnClear= new  QPushButton(this);
    btnClear->setGeometry(100,130, 100,30);
    btnClear->setText("Очистка");

    timer = new QTimer(this);
    timer->setInterval(1000);

    rad = new QRadioButton(this);
    rad->setGeometry(100,200, 100,30);
    rad->setText("Обратно");

    second = 0;

    connect(timer,SIGNAL(timeout()),this,SLOT(time()));
    connect(btnStart,SIGNAL(pressed()),this,SLOT(start()));
    connect(btnClear,SIGNAL(pressed()),this,SLOT(clear()));
    connect(edt,SIGNAL(textEdited(QString)),this,SLOT(change(QString)));
};

void MyWindow::time() {
     if (rad->isChecked()) {
         second++;
         lcd->display(second);
     }
     else {
     second--;
     lcd->display(second);
     }
}

void MyWindow::start() {
    timer->start();
}

void MyWindow::clear() {
    second=0;
    timer->stop();
    lcd->display(second);
}
void MyWindow::change(QString newText) {
    timer->stop();
    btnStart->setText("Старт");

    second = newText.toInt();
    lcd->display(second);
}



